package com.sdy.kzyy.biz.utils;

import com.sdy.common.utils.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 注释
 * </p>
 *
 * @author fb
 * @since 2020/3/24
 */
public class TimeChecker {

    public static boolean check(String interval, String week) {
        Date dateN = new Date();
        String nowWeek = String.valueOf(DateUtil.dateToWeek(dateN));
        if(!week.contains(nowWeek)) {
            return false;
        }
        String beginS = interval.substring(0,5) + ":00";
        String endS = interval.substring(6) + ":00";
        Date beginDate = null;
        Date endDate = null;
        Date nowDate = null;
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try {
            beginDate = sdf.parse(beginS);
            endDate = sdf.parse(endS);
            nowDate = sdf.parse(sdf.format(dateN));
        } catch (Exception e) {
            return false;
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowDate);
        Calendar begin = Calendar.getInstance();
        begin.setTime(beginDate);
        Calendar end = Calendar.getInstance();
        end.setTime(endDate);
        if (!date.after(end) && !date.before(begin)) {
            return true;
        }
        return false;
    }

}
